﻿Imports System.Data.SqlClient

Public Class Dechargement

    Private user As String
    Private userSite As String
    Private cn As CnData
    Private da As SqlDataAdapter
    Private ds As DataSet
    Private cmd As SqlCommand
    Private dtr As SqlDataReader

    Public Sub New(ByVal user As String, ByRef cn As CnData, ByVal userSite As String)
        ' Cet appel est requis par le concepteur.
        InitializeComponent()

        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
        Me.user = user
        Me.cn = cn
        Me.userSite = userSite

    End Sub

    Private Sub Fermer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fermer.Click
        Me.Close()
    End Sub

    Private Sub Reception_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reception.Click
        Dim ChildForm As New Reception(user, cn, userSite, chargement.Text, False)
        If ChildForm.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.Close()
        End If
    End Sub

    Private Sub chargement_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles chargement.KeyDown
        If e.KeyCode = Keys.Enter Then
            If String.IsNullOrEmpty(chargement.Text) Then
                MsgBox("Veuiller saisir le numéro de chargement")
                Exit Sub
            End If
            If Not IsNumeric(chargement.Text) Or chargement.Text.Length <> 16 Then
                MsgBox("Saisie incorrecte")
                Exit Sub
            End If
            cn.Open()
            cmd = New SqlCommand("SELECT Chargements.Chargement,Chargements.destinataire, Sites.nomDoc AS SiteE, Sites_1.nomDoc AS SiteD, Chargements.DateExp, Chargements.HeureExp, Chargements.Statut, " _
                        & " Chargements.NbAgres, Chargements.NbColis, Chargements.TypeFlux, Chargements.DateRec, Chargements.HeureRec, Chargements.Plomb1, Chargements.Plomb2, " _
                        & " Chargements.Transporteur, Chargements.Immatriculation, Chargements.Chauffeur " _
                        & " FROM Sites RIGHT OUTER JOIN " _
                        & " Chargements ON Sites.NumSite = Chargements.Expediteur LEFT OUTER JOIN " _
                        & " Sites AS Sites_1 ON Chargements.Destinataire = Sites_1.NumSite " _
                        & " WHERE chargement='" & chargement.Text & "'", cn.getCn)
            dtr = cmd.ExecuteReader()
            If Not dtr.HasRows Then
                MsgBox("Aucun chargement trouvé")
                GoTo fin
            End If
            dtr.Read()
            NbAgres.Text = dtr("NbAgres").ToString
            NbColis.Text = dtr("NbColis").ToString
            Mono_Multi.Text = dtr("TypeFlux").ToString
            SiteE.Text = dtr("SiteE").ToString
            If Not IsDBNull(dtr("DateExp")) Then
                DateE.Text = FormatDateTime(dtr("DateExp").ToString, DateFormat.LongDate)
            Else
                DateE.Text = ""
            End If

            HeureE.Text = dtr("HeureExp").ToString
            SiteD.Text = dtr("SiteD").ToString
            If Not IsDBNull(dtr("DateRec")) Then
                DateD.Text = FormatDateTime(dtr("DateRec").ToString, DateFormat.LongDate)
            Else
                DateD.Text = ""
            End If
            'DateD.Text = FormatDateTime(dtr("DateRec").ToString, DateFormat.LongDate)
            HeureD.Text = dtr("HeureRec").ToString
            Plomb.Text = dtr("Plomb1") & "  " & dtr("Plomb2")
            Transporteur.Text = dtr("Transporteur")
            Immatriculation.Text = dtr("Immatriculation")
            Chauffeur.Text = dtr("Chauffeur")

            If dtr("Destinataire") <> userSite Then
                SiteD.ForeColor = Color.Red
                Reception.Enabled = False
            Else
                SiteD.ForeColor = Color.Black
                If IsDate(dtr("DateRec")) Then
                    Reception.Enabled = False
                Else
                    Reception.Enabled = True
                End If
            End If

            dtr.Close()

fin:
            cn.Close()
        End If
    End Sub



End Class